package com.zhb.lkd.controller;


import com.zhb.lkd.base.PageResponse;
import com.zhb.lkd.base.ResponseResult;
import com.zhb.lkd.exception.BusinessException;
import com.zhb.lkd.pojos.entity.Partner;
import com.zhb.lkd.pojos.entity.Region;
import com.zhb.lkd.pojos.vo.PartnerVo;
import com.zhb.lkd.service.IPartnerService;
import com.zhb.lkd.service.IRegionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 运营区域 前端控制器
 * </p>
 *
 * @author haibin
 * @since 2024-08-18
 */
@RestController
@RequestMapping("/api/vm-service/region")
@Slf4j
@Api(tags = "区域管理相关接口")
public class RegionController {
    @Resource
    private IRegionService regionService;

    @GetMapping("/search")
    @ApiOperation("区域搜索")
    public ResponseResult search(
            @RequestParam(defaultValue = "1") Integer pageIndex,
            @RequestParam(defaultValue = "10") Integer pageSize,
            String name) {
        log.info("区域搜索{}", pageIndex);
        PageResponse pageResponse = regionService.search(pageIndex,pageSize,name);
        return ResponseResult.ok(pageResponse);
    }


    @PostMapping("")
    @ApiOperation("新增区域")
    public ResponseResult create(@RequestBody Region region) {
        log.info("新增区域{}", region);
        regionService.create(region);
        return ResponseResult.ok();
    }


    @PutMapping()
    @ApiOperation("修改区域")
    public ResponseResult updateById(@RequestBody Region region) {
        log.info("修改区域{}", region);
        if (region.getId()==0||region.getId()==null){
            throw new BusinessException(500,"区域id不能为空");
        }
        boolean b = regionService.updateById(region);
        return ResponseResult.ok();
    }





}
